<template>
	<view class="newcontent">
		<mescroll-uni :scroll-y="true" :down="downOption" @down="downCallback" :up="upOption" @up="upCallback">
			<view class="allowRefresh">
				<view v-for="(data,index) in newsList.list" :key="index" class="index-item" @click="bindClick(data.id,data.link)">
					<view v-if="data.class == 'noimg'" :class="data.class">
						<view :class="'newtitle fontsize'+fontsizenub">{{data.title}}</view>
						<view class="commonshow">
							<view class="seenub"><text class="'nubdata">{{data.uploadTime}}</text></view>
							<view class="seenub" v-if="data.label"><text class="'nubdata">{{data.label}}</text></view>
						</view>
					</view>
					<view v-if="data.class == 'oneimg'"  :class="[data.class,'oneimger']">
						<view class=".imgfather">
							<image :src="localurl+data.picture" class="imageonly"/></image>
						</view>
						<view class="oneimgbox">
							<view :class="'newtitle fontsize'+fontsizenub">{{data.title}}</view>
							<view class="commonshow">
								<view class="seenub"><text class="'nubdata">{{data.uploadTime}}</text></view>
								<view class="seenub" v-if="data.label"><text class="'nubdata">{{data.label}}</text></view>
							</view>
						</view>
					</view>
				</view>
				<view class="uni-tab-bar-loading">
					<view class="loading-more">{{newsList.loadingText}}</view>
				</view>
			</view>	
		</mescroll-uni>	
	</view>
</template>

<script>
	import {common} from '@/common/publish.js';
	import {mapState,mapMutations} from 'vuex';
	import MescrollUni from "mescroll-uni";
	export default {
		data() {
			return {
				newsList:{
					list:[],
					offset: 0,
					limit: 10,
					loadingText: '加载中...'
				},
				localurl:common.url,
				id:""
			};
		},
		components:{
			MescrollUni
		},
		onLoad(options){
			uni.setNavigationBarTitle({
				title: options.title
			});
			let id = options.id
			this.id = options.id;
			this.getList(mescroll,id)
		},
		computed: {
			...mapState(['fontsizenub'])
		},
		methods:{
			//刷新
			downCallback(mescroll){
				this.newsList.offset = 0;
				this.getList(mescroll,this.id)
			},
			upCallback(mescroll){
				
				this.getList(mescroll,this.id);
			},
			getList(mescroll,id){
				console.log(this.newsList.offset)
				uni.request({
					url:common.url+'/api/Frontiers/secondList.json',
					data:{
						offset: this.newsList.offset,
						limit: 10,
						relationid:id
					},
					success:(res)=>{
						if(res.statusCode == 200){
							res.data.rows.forEach((v)=>{
								if(v.picture == ""){
									v.class = 'noimg'
								}else{
									v.class = 'oneimg'
								}
								if(v.label && v.label.length>7)v.label = v.label.substring(0,6) + '...';
								this.newsList.list.push(v)
							})
							this.newsList.offset = parseInt(this.newsList.offset) + parseInt(res.data.limit);
							this.newsList.total = res.data.total;
							if (this.newsList.offset >= this.newsList.total) {
								this.newsList.loadingText = '没有更多数据了'
								mescroll.endSuccess(10,false)
							} else {
								this.newsList.loadingText = '下拉加载更多'
								mescroll.endSuccess(10,true)
							}
						}
					}
				})
			},
			bindClick(id,link){
				if(link){
					//如果连接存在 ==》 外链
					var	reg = /(http:\/\/|https:\/\/)((\w|=|\?|\.|\/|&|-)+)/g;
					var wherefrom = reg.test(link);
					if(wherefrom){
						uni.navigateTo({
							url:'/pages/turnLink/turnLink?type=index&link='+encodeURIComponent(JSON.stringify(link))
						})
					}else{
						console.log('111')
						uni.navigateTo({
							url: '/pages/xq/xq?type=qyzt&id='+id
						});
					}	
				}else{
					//本地
					uni.navigateTo({
						url: '/pages/xq/xq?type=qyzt&id='+id
					});
				}
			}
		}
		
	}
</script>

<style lang="scss">
	@import '../.././static/iconfont.css';
	@import '@/common/publish.scss';
	@include fontsizefn(".newtitle",32upx);
	.nubdata{
		font-size:28upx;
	}
	.mescroll-upwarp{
		display: none;
	}
</style>
